// import { REQUEST, SUCCESS, FAILURE } from 'shared/util/action-type.util';
import { Action } from 'config/interface';

const namespace = 'authentication';
export const ACTION_TYPES = {
  LOGIN: `${namespace}/LOGIN`,
  GET_SESSION: `${namespace}/GET_SESSION`,
  CLEAR_AUTH: `${namespace}/CLEAR_AUTH`,
};

const initialState = {
  loading: false,
  isAuthenticated: false,
  loginSuccess: false,
  loginError: false,
  sessionHasBeenFetched: false,
};

export type AuthenticationState = Readonly<typeof initialState>;

// Reducer

export default function reducer(
  state: AuthenticationState = initialState, action:Action,
): AuthenticationState {
  switch (action.type) {
    case ACTION_TYPES.CLEAR_AUTH:
      return {
        ...state,
        loading: false,
        isAuthenticated: false,
      };
    default:
      return state;
  }
}
